package com.bjsxt.usersCenter.back.util;

import java.util.Date;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.usersCenter.common.util.ConstatFinalUtil;
import com.bjsxt.usersCenter.common.util.DateFormatUtil;
@Component("taskUtil")
public class TaskUtil
{
	public void run()
	{
		ConstatFinalUtil.LOGGER.info("任务调度开始");
		
		this.cleanToken();
		
		ConstatFinalUtil.LOGGER.info("任务调度结束");
	}
	
	
	public void cleanToken()
	{
		DateFormatUtil dateFormatUtil=new DateFormatUtil();
		ConstatFinalUtil.LOGGER.info("清理token开始");
		Set set= ConstatFinalUtil.TOKENS_MAP.entrySet();
		for ( Object o :set)
		{
			Entry entry =(Entry) o;
			String token=entry.getKey()+"";
			JSONObject adminsJSON=(JSONObject) entry.getValue();
			Date validate=dateFormatUtil.parse(adminsJSON.get("validate")+"");
			if(System.currentTimeMillis()-validate.getTime()>1000*60*2)
			{
				ConstatFinalUtil.TOKENS_MAP.remove(token);
			}
		
		
		}
		
		ConstatFinalUtil.LOGGER.info("清理token结束");
		
	}
}
